<?php
	include_once "dataservice.php";
	
	class chude_db
	{
		public function Them($TenChuDe, $MaTrangThai, $PIN)
		{
			$sql = "INSERT INTO `tbl_chude`(`TenChuDe`, `MaTrangThai`, `PIN`) 
					VALUES ('$TenChuDe', '$MaTrangThai', '$PIN')";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($MaChuDe, $TenChuDe, $MaTrangThai, $PIN)
		{
			$sql = "UPDATE 	`tbl_chude` 
					SET 	`TenChuDe`    = '$TenChuDe',
							`MaTrangThai` = '$MaTrangThai',
							`PIN`         = '$PIN'
					WHERE 	`MaChuDe`='$MaChuDe'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function Xoa($MaChuDe)
		{
			$sql = "DELETE FROM `tbl_chude` WHERE `MaChuDe` = '$MaChuDe'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaChuDe, $MaTrangThai)
		{
			$sql = "SELECT * FROM tbl_chude WHERE 1";
			
			if($MaChuDe != 0)
				$sql .= " AND `MaChuDe` = $MaChuDe";
			if($MaTrangThai != -1)
				$sql .= " AND `MaTrangThai` = $MaTrangThai";
			
			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}
		public function LayTenChuDeTheoMaChuDe($MaChuDe)
		{
			$sql = "SELECT `TenChuDe` FROM `tbl_chude` WHERE `MaChuDe` = '$MaChuDe'";
			
			$service = new dataservice();
			return $service->ExecuteScalar($sql);
		}
	}
?>